package org.xiaoyu.rpc;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * Created By Have
 * 2021/7/12 20:39
 */
public abstract class AbstractExporter<T> implements Exporter<T> {
    protected final Logger logger = LoggerFactory.getLogger(getClass());

    private final Invoker<T> invoker;

    private volatile boolean unexporter = false;

    public AbstractExporter(Invoker<T> invoker) {
        if (invoker == null) {
            throw new IllegalStateException("service Invoker == null");
        }
        if (invoker.getInterface() == null) {
            throw new IllegalStateException("service type == null");
        }
        this.invoker = invoker;
    }

    @Override
    public Invoker<T> getInvoker() {
        return invoker;
    }

    @Override
    public void unexport() {
        if (unexporter) {
            return;
        }
        unexporter = true;
        getInvoker().destroy();
    }

    public void afterUnExport() {

    }

    @Override
    public String toString() {
        return getInvoker().toString();
    }
}
